package org.example.coupon.controller;


import org.example.core.utils.PageUtils;
import org.example.core.utils.R;
import org.example.coupon.vo.SRelationVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.example.coupon.entity.SeckillSessionEntity;
import org.example.coupon.service.SeckillSessionService;

import java.util.List;


/**
 * @author xiaojie_cc
 * @version 1.0
 */
@RestController
@RequestMapping("sms/backend/sSession")
public class SeckillSessionController {
    @Autowired
    private SeckillSessionService seckillSessionService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R<?> list(@RequestParam(defaultValue = "1") Integer pageNum
            ,@RequestParam(defaultValue = "10") Integer pageSize
            ,@RequestParam(required = false) String name
            ,@RequestParam(required = false) Integer status ){
        PageUtils pageUtils = seckillSessionService.querySeckillSessionList(pageNum, pageSize, name, status);
        return R.ok(pageUtils);
    }


    @GetMapping("/selectList/{promotionId}")
    public R<?> selectList(@PathVariable("promotionId")Long promotionId){
        List<SRelationVo> relationVos = seckillSessionService.querySelectSeckillSession(promotionId);
        return R.ok(relationVos);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R<?> info(@PathVariable("id") Long id){
        SeckillSessionEntity seckillSession = seckillSessionService.querySeckillSessionInfo(id);
        return R.ok(seckillSession);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R<?> save(@RequestBody SeckillSessionEntity seckillSession){
        return seckillSessionService.addSeckillSession(seckillSession);
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R<?> update(@RequestBody SeckillSessionEntity seckillSession){
        return seckillSessionService.updateSeckillSession(seckillSession);
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R<?> delete(@RequestBody Long[] ids){
        return null;
    }

}
